<template>
	<!-- 预核保工作列表-预核保详情页面 -->
	<div class="fillcontain bgfff">
		<div class="contain baseInfo">
			<el-form label-width="120px">
				<el-row class="mt20">
					<el-col :span="6">
						<el-form-item label="案件号">
							<el-input disabled v-model="caseNum" ></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="保单号">
							<el-input disabled v-model=" policy.policyNo" ></el-input>
						</el-form-item>
					</el-col>
				</el-row>
			</el-form>
		</div>

		<!-- 被保险人 -->
		<div class="contain baseInfo">
			<div class="title"><span>被保险人</span></div>
			<el-form label-width="120px">
				<el-row class="mt20">
					<el-col :span="6">
						<el-form-item label="姓名">
							<el-input disabled v-model=" name" ></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="证件号码">
							<el-input disabled v-model=" idNo" ></el-input>
						</el-form-item>
					</el-col>
					<el-col :span="6">
						<el-form-item label="证件类型">
							<el-input disabled v-model="idTypeName" ></el-input>
						</el-form-item>
					</el-col>
					<!--                        <el-col :span="6">
                            <el-form-item label="性别">
                                <el-input disabled placeholder="性别"></el-input>
                            </el-form-item>
                        </el-col> -->
					<el-col :span="6">
						<el-form-item label="职业">
							<el-input disabled v-model="occupationName" ></el-input>
						</el-form-item>
					</el-col>
					<!-- <el-col :span="6">
                            <el-form-item label="受薪人士">
                                <el-input disabled placeholder="受薪人士"></el-input>
                            </el-form-item>
                        </el-col>
                        <el-col :span="6">
                            <el-form-item label="特殊人群">
                                <el-input disabled placeholder="特殊人群"></el-input>
                            </el-form-item>
                        </el-col> -->
				</el-row>
			</el-form>
		</div>

		<!-- 保险计划 -->
		<div class="contain baseInfo">
			<div class="title"><span>保险计划</span></div>
			<div class="table_container">
				<el-table :data="tableData" show-summary style="width: 100%">
					<el-table-column prop="type" :formatter="changeType" label="类型" min-width="180" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="life" label="寿险LIFE（万元）" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="dd" label="重疾DD/WP/PB（万元）" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="wp" label="豁免重疾WP（万元）" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="pa" label="意外险PA（万元）" min-width="120" show-overflow-tooltip>
					</el-table-column>
				</el-table>
			</div>
		</div>

		<!-- 理赔史 -->
		<div class="contain baseInfo">
			<div class="title"><span>理赔史</span></div>
			<el-row class="20">
				<el-col :span="24">
					<el-input disabled v-model=" caseAssess.claimsHistory" type="textarea"></el-input>
				</el-col>
			</el-row>
		</div>

		<!-- 医务信息 -->
		<div class="contain">
			<div class="title"><span>医务信息</span></div>
			<el-tabs type="card" v-model="activeNameA">
				<el-tab-pane label="健康告知" name="first">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.healtNotify"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="既往体检报告" name="second">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.pastMedicallReport"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="达标体检" name="third">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.reachMedicallReport"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
		</div>

		<!-- 财务信息 -->
		<div class="contain">
			<div class="title"><span>财务信息</span></div>
			<el-tabs type="card">
				<el-tab-pane label="收入类" name="four">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.income"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="资产类" name="five">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.assets"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="第三方平台、公众平台信息(正面)" name="six">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.positiveMessage"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="第三方平台、公众平台信息(负面)" name="seven">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.negativeMessage"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
		</div>

		<!-- 排查信息 -->
		<div class="contain">
			<div class="title"><span>排查信息</span></div>
			<el-tabs type="card">
				<el-tab-pane label="同业排查" name="eight">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.typc"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="医保排查" name="nine">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.ybpc"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="生存调查" name="ten">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.scpc"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
		</div>
		<!-- 综合结论 -->
		<div class="contain">
			<div class="title"><span>预核保综合评估意见</span></div>
			<el-tabs type="card">
				<el-tab-pane label="医务评估" name="eleven">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.ywpg"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="财务评估" name="twelve">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.cwpg"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
				<el-tab-pane label="综合小结" name="thirteen">
					<el-row class="20">
						<el-col :span="24">
							<el-input type="textarea" disabled v-model=" caseAssess.zhxj"></el-input>
						</el-col>
					</el-row>
				</el-tab-pane>
			</el-tabs>
		</div>

		<!-- 影像列表 -->
		<div class="contain">
			<div class="title"><span>影像列表</span></div>
			<div class="table_container">
				<el-table :data="caseFile" style="width: 100%">
					<el-table-column type="index" label="序号" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="origName" label="文件名称" min-width="200" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="path" v-if="false" label="文件原路径" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column prop="caseId" v-if="false" label="文件案件号" min-width="120" show-overflow-tooltip>
					</el-table-column>
					<el-table-column width="100" label="操作">
						<template slot-scope="scope">
							<!-- <el-button type="primary" icon="el-icon-download"></el-button> -->
							<span class="operationIcon" @click="download(scope.row)">
								<!-- 下载 -->
								<el-tooltip class="item" effect="light" content="下载" placement="top">
									<i class="el-icon-download"></i>
								</el-tooltip>
							</span>
						</template>
					</el-table-column>
				</el-table>
			</div>
		</div>

		<!-- 签名栏目 -->
		<div class="contain mt10 bgf9f9f9">
			<div class="title">
				<el-row class="pt15 pb15">
					<el-col :span="12" class="text_center">高净值业务部预核保专家：
						{{ busUserName}}
					</el-col>
					<el-col :span="12" class="text_center">填写日期：{{dealTime}}</el-col>
				</el-row>
			</div>
		</div>
		<!-- 核保意见 -->
		<div class="contain mt10">
			<div class="title">
				<span>核保意见</span>
			</div>
			<div class="table_container">
				<el-table :data="eurgs">
					<el-table-column prop="opinion" label="核保意见"></el-table-column>
					<el-table-column prop="underwritingTime" label="日期"></el-table-column>
					<el-table-column prop="underwritingPerson" label="核保员"></el-table-column>
				</el-table>
				<!-- 操作按钮 -->
<!-- 				<el-row v-if="showAdd">
					<el-col :span="24" class="pb15 pt15">
						<el-button  type="danger" plain @click="showInput">新增</el-button>
					</el-col>
				</el-row> -->
				<el-row v-if="showAddButton">
					<el-col :span="24">
						<el-input clearable type="textarea" :rows="2" v-model="bmntdesc" placeholder="请输入内容"></el-input>
					</el-col>
				</el-row>
			</div>
			<!-- 按钮 -->
			<div class="contain text_center" v-if="showAddButton">
				<el-button type="danger" @click="goBack">返 回</el-button>
				<el-button type="danger" class="Defaultbutton" @click="submit()">提交</el-button>
			</div>
		</div>


	</div>
</template>

<script>
	import TaskConstants, {
		call,exportData
	} from "@/api/taskManager/common"
	import constant from '@/utils/constant';
	import moment from 'moment';
	import { getToken } from '@/utils/auth' // 验权(从cookie中获取)
	export default {
		data() {
			return {
				activeNameA: 'first',
				activeNameB: 'first',
				activeNameC: 'first',
				tableData: [],
				userInfo:{},
				caseFile: [],
				bmntdesc: '',
				taskNo: '',
				planType: TaskConstants.prePlanType,
				occType: TaskConstants.preOccType,
				idType: TaskConstants.preIdType,
				prepNo: '',
				routeid:'',
				caseNum:'',
				dealTime:'',
				activeName: {},
				eurgs: [],
				now: moment().format("YYYY-MM-DD"),
				occupationName: '',
				idTypeName: '',
				showAdd: false,
				showAddButton:false,
				busUserName: '',
				busUserCompany: '',
				busUserChannel: '',
				name: '',
				idNo: '',
				policy: {
					policyNo: '',
					insuranceName: '',
				},
				caseAssess: {
					claimsHistory: '',
					healtNotify: '',
					pastMedicallReport: '',
					reachMedicallReport: '',
					income: '',
					assets: '',
					positiveMessage: '',
					negativeMessage: '',
					typc: '',
					ybpc: '',
					scpc: '',
					ywpg: '',
					cwpg: '',
					zhxj: ''
				}, //專家系統返回的案件詳情
				loading: false,
			}
		},
		created() {
			this.userInfo=JSON.parse(localStorage.getItem(getToken('token'))).userKeyInfo;
		},
		methods: {
			goBack(){
				this.$router.back(-1);
			},
			show() {
				this.$store.dispatch('loading/CHANGE_LOADING', true);
			},
			cancle() {
				this.$store.dispatch('loading/CHANGE_LOADING', false)
			},
			/* b保險計劃類型 */
			changeType: function(row) {
				for (let item in this.planType) {
					if (row.type.toUpperCase() == this.planType[item]["key"]) {
						return this.planType[item]["name"];
					}
				}
				return row.type;
			},
			changeIdType(value) {
				for (let item in this.idType) {
					if (value == this.idType[item]["key"]) {
						value = this.idType[item]["name"];
						break;
					}
				}
				return value;
			},
			/* 职业转化 */
			changeOccType(value) {
				for (let item in this.occType) {
					if (value == this.occType[item]["key"]) {
						value = this.occType[item]["name"];
						break;
					}
				}
				return value;
			},
			submit() {
				let content = this.bmntdesc;
				if ( "" == content || content.length == 0) {
					this.$message.error("请输入核保意见");
					return;
				}
				this.show();
				call(TaskConstants.apis.addConment, {
					content: this.bmntdesc,
					taskno: this.taskNo,
					caseId: this.prepNo
				}, "post").then(res => {
					this.cancle();
					if (res.resultCode == constant.SUCCESS ) {
						this.$message.success("新增核保意见完成！");
						let item = {
							opinion: this.bmntdesc,
							underwritingTime: moment().format("YYYY-MM-DD HH:mm:ss"),
							underwritingPerson: this.userInfo.account
						};
						this.eurgs.push(item);
					} else {
						this.$message.error(res.resultMsg);
					}
					this.bmntdesc ="";
				}).catch(err => {
					this.cancle();
					this.$message.error("调用预核保专家系统超时，请稍后重试！");
				})
			},
			queryDetial() {
				this.show();
				this.tableData = [];
				this.caseFile = [];
				call(TaskConstants.apis.getCaseDetail + this.prepNo).then(res => {
					if (res.resultCode == constant.SUCCESS ) {
						let resData = res.data;
						this.name = resData["name"];
						this.busUserName = resData["busUserName"];
						this.busUserCompany = resData["busUserCompany"];
						this.idNo = resData["idNo"];
						let policy = resData["policy"];
						if (undefined != policy && "" != policy && "undefined" != policy) {
							this.policy.policyNo = policy["policyNo"];
							this.policy.insuranceName = policy["insuranceName"];
						}
						let caseAssess = resData["caseAssess"];
						if (undefined != caseAssess && "" != caseAssess && "undefined" != caseAssess) {
							this.caseAssess.claimsHistory = caseAssess["claimsHistory"];
							this.caseAssess.healtNotify = caseAssess["healtNotify"];
							this.caseAssess.pastMedicallReport = caseAssess["pastMedicallReport"];
							this.caseAssess.reachMedicallReport = caseAssess["reachMedicallReport"];
							this.caseAssess.income = caseAssess["income"];
							this.caseAssess.assets = caseAssess["assets"];
							this.caseAssess.positiveMessage = caseAssess["positiveMessage"];
							this.caseAssess.negativeMessage = caseAssess["negativeMessage"];
							this.caseAssess.typc = caseAssess["typc"];
							this.caseAssess.ybpc = caseAssess["ybpc"];
							this.caseAssess.scpc = caseAssess["scpc"];
							this.caseAssess.ywpg = caseAssess["ywpg"];
							this.caseAssess.cwpg = caseAssess["cwpg"];
							this.caseAssess.zhxj = caseAssess["zhxj"];
						}
						this.occupationName = this.changeOccType(resData["occupationCode"]);
						this.idTypeName = this.changeIdType(resData["idType"]);
						let caseAssessPlans =  resData["caseAssessPlans"];
						if(undefined != caseAssessPlans &&"" != caseAssessPlans && "undefined" != caseAssessPlans){
							caseAssessPlans.forEach(item => {
								this.tableData.push(item);
							})
						}
						let insures = resData["insures"];
						if (undefined != insures && null != insures &&"undefined" != insures) {
							insures.forEach( item =>{
								this.caseFile.push(item);
							})
						}
						let finances = resData["finances"]
						if (undefined != finances && null != finances && "undefined" != finances) {
							finances.forEach( item =>{
								this.caseFile.push(item);
							})
						}
						let medicals = resData["medicals"]
						if (undefined != medicals && null != medicals && "undefined" != medicals) {
							medicals.forEach( item =>{
								this.caseFile.push(item);
							});
						}
					} 
					this.cancle();
				}).catch(err => {
					this.cancle();
					this.$message.error("调用预核保专家系统超时，请稍后重试！");
				})
			},
			/* 获取核保意见列表 */
			queryContents(){
				this.show();
				let param ="?taskno="+this.taskNo
				call(TaskConstants.apis.queryContents+param).then( result =>{
					if (result.resultCode == constant.SUCCESS && result.data ) {
						this.eurgs=result.data;
					}	
				})
			},
			download(row) {
				let title = row.origName;
				title = title.substring(0,title.lastIndexOf("."));
				let path = row.path;
				let prefix = path.substring(path.lastIndexOf(".") ,path.length );
				let param = "?path="+path+"&name="+title;
				let vueObj = this;
				exportData(vueObj,TaskConstants.apis.downloadImage+param,null, "get",row.origName,"application/octet-stream");
			}
		},
		activated() {
			if(undefined !=this.$route.params.prepNo && "" !=this.$route.params.prepNo) {
				this.prepNo = this.$route.params.prepNo;
				this.taskNo = this.$route.params.taskNo;
				this.routeid = this.$route.params.routeid;
				let caseNu = this.$route.params.caseNum;
				if(caseNu ==null ||caseNu =="null") {
					this.caseNum = "";
				} else {
					this.caseNum = caseNu;
				}
				this.dealTime = this.$route.params.dealTime;
				if (this.routeid =="end") {
					this.showAdd = false;
					this.showAddButton =false;
				} else {
					this.showAdd = true;
					this.showAddButton = true;
					
				}
				this.queryDetial();
				this.queryContents();
			}
		},
		// watch: {
		// 	prepNo:function(newValue) {
		// 		if(undefined !=newValue && "" !=newValue ) {
		// 			this.queryDetial();
		// 			this.queryContents();
		// 		}
		// 	}
		// }
	}
</script>

<style lang="less" scoped>
	.fillcontain {
		padding-bottom: 0;
	}

	.contain {
		background: #fff;
		padding: 10px;
	}
</style>
